package net.jjjshop.shop.service.shop.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.jjjshop.common.cache.RedisUtil;
import net.jjjshop.common.entity.lbt.LbLotteryManager;
import net.jjjshop.common.entity.page.CenterMenu;
import net.jjjshop.common.mapper.lbt.LbLotteryManagerMapper;
import net.jjjshop.common.service.lbt.LbSysConfigService;
import net.jjjshop.common.service.user.UserService;
import net.jjjshop.common.util.CentMenuUtils;
import net.jjjshop.framework.core.pagination.PageInfo;
import net.jjjshop.framework.core.pagination.Paging;
import net.jjjshop.shop.param.CommonPageParam;
import net.jjjshop.shop.service.shop.LbLotteryManagerService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


/**
 * 第三个模块抽奖池
 */

@Service("LbLotteryManagerService")
public class LbLotteryManagerServiceImpl extends ServiceImpl<LbLotteryManagerMapper, LbLotteryManager> implements LbLotteryManagerService {

    @Autowired
    private LbLotteryManagerMapper dao;


    @Override
    public List<LbLotteryManager> getLotteryManagerRecord() {
        return dao.getLotteryRecord();
    }



    /**
     * 列表
     * @param commonPageParam
     * @return
     */
    @Override
    public Paging<LbLotteryManager> getList(CommonPageParam commonPageParam){
        // 是否存在
        if(this.count(new LambdaQueryWrapper<LbLotteryManager>()) == 0){
            this.insertDefault();
        }
        Page<LbLotteryManager> page = new PageInfo<>(commonPageParam);
        IPage<LbLotteryManager> iPage = this.page(page, new LambdaQueryWrapper<LbLotteryManager>()
                .orderByAsc(LbLotteryManager::getTitle));
        return new Paging(iPage);
    }

    /**
     * 插入默认数据
     * @param
     * @return
     */
    private void insertDefault(){

    }

    /**
     * 新增
     * @param centerParam
     * @return
     */
    public Boolean add(LbLotteryManager centerParam){
        LbLotteryManager menu = new LbLotteryManager();
        centerParam.setCreateTime(new Date());

        BeanUtils.copyProperties(centerParam, menu);
        return this.save(menu);
    }

    /**
     * 修改显示状态
     * @param menuId
     * @param isShow
     * @return
     */
    public Boolean status(Integer menuId, Integer isShow){
        LbLotteryManager byId = getById(menuId);
        byId.setIsShow(isShow);
        return this.updateById(byId);
    }

    /**
     * 修改
     * @param centerParam
     * @return
     */
    public Boolean edit(LbLotteryManager centerParam){
        LbLotteryManager menu = new LbLotteryManager();
        BeanUtils.copyProperties(centerParam, menu);
        return this.updateById(menu);
    }

    /**
     * 删除
     * @param menuId
     * @return
     */
    public Boolean delById(Integer menuId){
        return this.removeById(menuId);
    }




}
